package es.cea.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class ServletIntro extends  HttpServlet{
	
	private static final long serialVersionUID = 1L;
	
	public ServletIntro(){
		super();
	}
	
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		HttpSession sesion = request.getSession();
		ServletContext servletContext = sesion.getServletContext();
		
		PrintWriter writer = response.getWriter();
		
		//Obtenemos del contexto los colores
		@SuppressWarnings("unchecked")
		ArrayList<String> colores = (ArrayList<String>) servletContext.getAttribute("colores");
				
		writer.println("<html><head><meta http-equiv='Content-type' content='text/html; charset=utf-8'>"
				+ "</head>" + "<body>");
		
		writer.println("<form action='Chat' method ='GET'>");
		writer.println("<label for = 'textUsuario'>Usuario</label><input type='text' name ='textUsuario'></br>");
		writer.println("<label for ='selectColores'> Selecciona un color </label> <select name ='selectColores'>");
			for (String color: colores){
				writer.println("<option value = '" + color + "'>" + color + "</option>");
			}
				
		writer.println("</select></br>");
		writer.println("<input type ='submit' value = 'Enviar'>");
		
		writer.println("</form>");
		
		writer.println("</body></html>");
		
	}

}
